﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Hidden/Wave"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_distanceFactor("distanceFactor", float) = 1
		_totalFactor("totalFactor", float) = 1
		_timeScale("timeScale", float) = 1
	}
	SubShader
	{

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				return o;
			}

			sampler2D _MainTex;
			float _distanceFactor;
			float _totalFactor;
			float _timeScale;

			fixed4 frag (v2f i) : SV_Target
			{
				fixed2 dv = fixed2(0.5, 0.5) - i.uv;
				dv = dv * float2(_ScreenParams.x / _ScreenParams.y, 1);

				fixed dis = length(dv);

				float sin_val = sin(dis * _distanceFactor + _Time.x * _timeScale) * _totalFactor * 0.01;
				float cos_val = cos(dis * _distanceFactor + _Time.x * _timeScale) * _totalFactor * 0.01;

				fixed2 dv1 = normalize(dis);

				fixed2 offset = fixed2(dv1.x * sin_val, dv1.y*cos_val);

				fixed2 uv = offset + i.uv;

				fixed4 col = tex2D(_MainTex, uv);

				return col;
			}
			ENDCG
		}
	}
}
